package com.itdct.onflow.generator.util

import cn.hutool.core.io.FileUtil
import com.itdct.onflow.core.util.TimeUtil
import com.itdct.onflow.generator.config.GeneratorConfig
import com.itdct.onflow.generator.context.GeneratorContext
import java.io.File
import java.nio.charset.Charset
import java.util.*

/**
 * @author Zhouwx
 * @date 2025/9/8 17:55:31
 * @version 1.0
 * @description
 */
object GeneratorLogUtil {
    fun appendSql(sql: String, context: GeneratorContext, generatorConfig: GeneratorConfig) {
        if (!generatorConfig.generateSql) {
            return
        }

        val sqlFilePath = context.sqlFilePath
        val classModel = context.classModel
        val sqlFile = File(sqlFilePath)
        val infoSql = """
-- OnflowGenerator: 更新类：${classModel.fullClassName}
-- 更新时间：${TimeUtil.dateToTimeString(Date(), TimeUtil.yyyyMMddHHmmss_HYPHEN)}，更新人：${generatorConfig.authorName}
${sql}

        """.trimIndent()
        FileUtil.appendString(infoSql, sqlFile, Charset.defaultCharset())
    }
}